home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Tools / ClassAct / Examples / Chooser / hiddenchooser.c < prev    next >
C/C++ Source or Header  |  2002-07-02  |  6KB  |  226 lines

  1. ;/* Hidden Chooser Example
  2. sc link hiddenchooser.c lib lib:classact.lib
  3. quit
  4.  */
  5.  
  6. /** This example demonstrates the "hidden mode" mode of the chooser gadget.
  7.  **
  8.  ** It is a NEW mode added recently to ClassAct release 2.0 - you *must*
  9.  ** have atleast V41.101 or later installed. Officially, this is a V42
  10.  ** ClassAct 2.1 feature, but made available now due to developer demand.
  11.  **
  12.  ** Hidden choosers currently need to be handled differently than visible
  13.  ** gadget objects. Since they are NOT added to the window, or layout group,
  14.  ** they do not trigger a GADGETUP. So, you must use an IDCMPUPDATE hook
  15.  ** and use the CHOOSER_Active notifications to get the selection.
  16.  **/
  17.  
  18. #define USE_BUILTIN_MATH
  19. #define USE_SYSBASE
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <math.h>
  24.  
  25. #define    INTUI_V36_NAMES_ONLY
  26.  
  27. #include <exec/types.h>
  28. #include <exec/memory.h>
  29. #include <dos/dos.h>
  30. #include <dos/dosextens.h>
  31. #include <intuition/intuition.h>
  32. #include <intuition/gadgetclass.h>
  33. #include <intuition/intuitionbase.h>
  34. #include <intuition/classusr.h>
  35. #include <intuition/imageclass.h>
  36. #include <intuition/gadgetclass.h>
  37. #include <intuition/icclass.h>
  38. #include <intuition/cghooks.h>
  39. #include <intuition/classes.h>
  40. #include <graphics/gfxbase.h>
  41. #include <graphics/text.h>
  42. #include <graphics/gfxmacros.h>
  43. #include <utility/tagitem.h>
  44. #include <utility/hooks.h>
  45.  
  46. #include <clib/macros.h>
  47.  
  48. #include <proto/intuition.h>
  49. #include <proto/graphics.h>
  50. #include <proto/dos.h>
  51. #include <proto/exec.h>
  52. #include <proto/utility.h>
  53.  
  54. #include <classact.h>
  55.  
  56. #define ID_BUTTON        1
  57. #define ID_HIDDEN        2
  58.  
  59. /* Labels for the popup.
  60.  */
  61. UBYTE *chooser_strs[] =
  62. {
  63.     "Save Image",
  64.     "Load Image",
  65.     "Follow URL",
  66.     "Save to HotList",
  67.     NULL
  68. };
  69.  
  70. /*************************************************************************
  71.  * IDCMP hook
  72.  */
  73.  
  74. void __asm __saveds IDCMPFunc(    register __a0 struct Hook *Hook,
  75.                                 register __a2 Object *Window,
  76.                                 register __a1 struct IntuiMessage *Msg )
  77. {
  78.     ULONG active;
  79.  
  80.     if (Msg->Class == IDCMP_IDCMPUPDATE)
  81.     {
  82.         /* The notification might include one of the tags we want to look at...
  83.          */
  84.         if      (GetTagData(GA_ID, 0, Msg->IAddress) == ID_HIDDEN)
  85.         {
  86.             active = GetTagData(CHOOSER_Active, -1, Msg->IAddress);
  87.             printf("active: %ld\n", active);
  88.         }
  89.     }
  90. }
  91.  
  92.  
  93. int main( int argc, char *argv[] )
  94. {
  95.     if (ButtonBase)
  96.     {
  97.         Object *Chooser_Object_Hidden;
  98.         Object *Window_Object;
  99.         struct Window *window;
  100.         struct List *chooserlist;
  101.         struct Hook idcmphook;
  102.  
  103.         idcmphook.h_Entry = (ULONG (* )())IDCMPFunc;
  104.         idcmphook.h_SubEntry = NULL;
  105.  
  106.         chooserlist = ChooserLabelsA(chooser_strs);
  107.  
  108.         if (chooserlist)
  109.         {
  110.             /*    Create an instance of the chooser class that will remain hidden.
  111.             */
  112.             Chooser_Object_Hidden = ChooserObject,
  113.                 GA_RelVerify, TRUE,
  114.                 GA_ID, ID_HIDDEN,
  115.                 CHOOSER_Labels, chooserlist,
  116.                 CHOOSER_DropDown, TRUE,
  117.                 CHOOSER_AutoFit, TRUE,
  118.                 CHOOSER_Hidden, TRUE,
  119.                 ICA_TARGET, ICTARGET_IDCMP,
  120.             ChooserEnd;
  121.  
  122.             /* Create the window object. */
  123.             Window_Object = WindowObject,
  124.                 WA_ScreenTitle, "ClassAct Release 2.0",
  125.                 WA_Title, "Another ClassAct chooser.gadget Example",
  126.                 WA_SizeGadget, TRUE,
  127.                 WA_Left, 40,
  128.                 WA_Top, 30,
  129.                 WA_DepthGadget, TRUE,
  130.                 WA_DragBar, TRUE,
  131.                 WA_CloseGadget, TRUE,
  132.                 WA_Activate, TRUE,
  133.                 WA_SmartRefresh, TRUE,
  134.                 WA_IDCMP, IDCMP_GADGETUP|IDCMP_GADGETDOWN|IDCMP_IDCMPUPDATE,
  135.                 WINDOW_IDCMPHook, &idcmphook,    /* For BOOPSI notification */
  136.                 WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE,
  137.                 WINDOW_ParentGroup, VGroupObject,
  138.                     LAYOUT_SpaceOuter, TRUE,
  139.                     LAYOUT_DeferLayout, TRUE,
  140.  
  141.                     LAYOUT_AddChild, ButtonObject,
  142.                         GA_RelVerify, TRUE,
  143.                         GA_ID, ID_BUTTON,
  144.                         GA_Text, "Press me to show the hidden chooser!",
  145.                     ButtonEnd,
  146.                     CHILD_WeightedHeight, 0,
  147.  
  148.                     LAYOUT_AddChild, VGroupObject,
  149.                         CLASSACT_BackFill, NULL,
  150.                         LAYOUT_SpaceOuter, TRUE,
  151.                         LAYOUT_VertAlignment, LALIGN_CENTER,
  152.                         LAYOUT_HorizAlignment, LALIGN_CENTER,
  153.                         LAYOUT_BevelStyle, BVS_FIELD,
  154.  
  155.                         LAYOUT_AddImage, LabelObject,
  156.                             LABEL_Text, "Selecting the button above will\n",
  157.                             LABEL_Text, "reveal the hidden popup chooser!\n\n",
  158.                             LABEL_Text, "Hidden choosers are useful for\n",
  159.                             LABEL_Text, "context sensitive quick menus.\n",
  160.                         LabelEnd,
  161.  
  162.                     LayoutEnd,
  163.                 LayoutEnd,
  164.             WindowEnd;
  165.  
  166.             /*  Object creation sucessful?
  167.              */
  168.             if( Window_Object )
  169.             {
  170.                 /*  Open the window.
  171.                  */
  172.                 if( window = (struct Window *) CA_OpenWindow(Window_Object) )
  173.                 {
  174.                     ULONG wait, signal, result, done = FALSE;
  175.                     WORD Code;
  176.                     
  177.                     /* Obtain the window wait signal mask.
  178.                      */
  179.                     GetAttr( WINDOW_SigMask, Window_Object, &signal );
  180.  
  181.                     /* Input Event Loop
  182.                      */
  183.                     while( !done )
  184.                     {
  185.                         wait = Wait(signal|SIGBREAKF_CTRL_C);
  186.                         
  187.                         if (wait & SIGBREAKF_CTRL_C) done = TRUE;
  188.                         else
  189.  
  190.                         while ((result = CA_HandleInput(Window_Object,&Code)) != WMHI_LASTMSG)
  191.                         {
  192.                             switch (result & WMHI_CLASSMASK)
  193.                             {
  194.                                 case WMHI_CLOSEWINDOW:
  195.                                     done = TRUE;
  196.                                     break;
  197.  
  198.                                 case WMHI_GADGETUP:
  199.                                     switch(result & WMHI_GADGETMASK)
  200.                                     {
  201.                                         case ID_BUTTON:
  202.                                             ActivateGadget((struct Gadget *)Chooser_Object_Hidden, window, NULL);
  203.                                             break;
  204.  
  205.                                     }
  206.                                     break;
  207.                             }
  208.                         }
  209.                     }
  210.                 }
  211.  
  212.                 /* Disposing of the window object will also close the window if it is
  213.                  * already opened and it will dispose of all objects attached to it.
  214.                  */
  215.                 DisposeObject( Window_Object );
  216.  
  217.                 /* The hidden chooser isn't attached to anything, so we must dispose
  218.                  * it ourselves...
  219.                  */
  220.                 DisposeObject( Chooser_Object_Hidden );
  221.             }
  222.         }
  223.         FreeChooserLabels(chooserlist);
  224.     }
  225. }
  226.